package com.dmw.controller;

import com.dmw.dto.Dto;
import com.dmw.service.PayConsumerService;
import com.dmw.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("pay/api/v")
public class PayController {

    @Autowired
    private PayConsumerService payConsumerService;

    @RequestMapping(value = "/wxpay/createqccode/{orderNo}", method = RequestMethod.GET)
    @ResponseBody
    public Object pay(@PathVariable String orderNo){
        System.out.println("微信支付");
        System.out.println(orderNo);
//        Map<String,Object> map=new HashMap<>();
//        map.put("orderNo",orderNo);
        return payConsumerService.createqccode(orderNo);
    }

    @RequestMapping(value = "/alipay/pay/{orderNo}", method = RequestMethod.GET)
    @ResponseBody
    public Object pay2(@PathVariable String orderNo){
        System.out.println("支付宝支付");
        System.out.println(orderNo);
        Map<String,Object> map=new HashMap<>();
        map.put("orderNo",orderNo);
        return payConsumerService.alipay(orderNo);
    }

    @RequestMapping(value = "/notify", method = RequestMethod.POST)
    @ResponseBody
    public Object callback(HttpServletRequest request,
                        HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        PayVo vo=new PayVo();
        vo.setRequest(request);
        vo.setResponse(response);
        return payConsumerService.callback(vo);
    }

}
